package main

import "fmt"

func printSlice(s []int) {
	fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s)
}

func printSlice2(s string, x []int) {
	fmt.Printf("%s length=%d cap=%d %v\n",
		s, len(x), cap(x), x)
}

func main() {
	slice1_1 := []int{2, 4, 6, 8, 10, 12, 14}
	printSlice(slice1_1)

	//对切片进行切片，使其长度为零
	slice1_2 := slice1_1[:0]
	printSlice(slice1_2) //len=0 cap=7 []

	//扩展其长度
	slice1_3 := slice1_1[:4]
	printSlice(slice1_3) //len=4 cap=7 [2 4 6 8]

	//舍弃前两个值
	slice1_4 := slice1_1[2:]
	printSlice(slice1_4) // len=5 cap=5 [6 8 10 12 14]

	slice2_1 := make([]int, 10)
	printSlice2("slice2_1", slice2_1) // slice2_1 length=10 cap=10 [0 0 0 0 0 0 0 0 0 0]

	slice2_2 := make([]int, 0, 10)
	printSlice2("slice2_2", slice2_2) // slice2_2 length=0 cap=10 []

	slice2_3 := slice2_2[:5]
	printSlice2("slice2_3", slice2_3) // slice2_3 length=5 cap=10 [0 0 0 0 0]

	slice2_4 := slice2_3[2:5]
	printSlice2("slice2_4", slice2_4) // slice2_4 length=3 cap=8 [0 0 0]
}
